import Vue from 'vue'
import VueRouter from 'vue-router'
import MyLogin from "@/pages/MyLogin";
import Home from "@/pages/Home";
import Overview from "@/pages/Overview";
import JobList from "@/pages/JobList";
import EmployeeList from "@/pages/EmployeeList";
import JobReport from "@/pages/JobReport";

Vue.use(VueRouter);

// 捕获push replace中的错误
// 当然在replace中的错误也是可以相同的进行捕获
const originalPush = VueRouter.prototype.push
const originalReplace = VueRouter.prototype.replace
// push
VueRouter.prototype.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
  return originalPush.call(this, location).catch(err => err)
}
// replace
VueRouter.prototype.replace = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalReplace.call(this, location, onResolve, onReject)
  return originalReplace.call(this, location).catch(err => err)
}

export default new VueRouter({
  routes: [
    {
      path:'/my-login',
      component:MyLogin
    },
    {
      path:'/home',
      component:Home,
      children:[
        {
          path:'overview',
          component:Overview,
        },
        {
          path:'job-list',
          component:JobList
        },
        {
          path:'employee-list',
          component:EmployeeList
        },
        {
          path:'job-report',
          component:JobReport
        }
      ]
    }
  ]
})

